package client;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Date;

import rentalStore.ClientSessionRemote;
import rentalStore.ManagerSessionRemote;
import rentalStore.SessionFactoryRemote;

public class Client extends AbstractScriptedTripTest<ClientSessionRemote, ManagerSessionRemote> {
        
        /********
         * MAIN *
         ********/
        private Registry registry;
        private SessionFactoryRemote sessionFactory;
        
        public static void main(String[] args) throws Exception {
                
                String carRentalCompanyName = "Hertz";
                
                // An example reservation scenario on car rental company 'Hertz' would be...
                Client client = new Client("trips", carRentalCompanyName);
                client.run();
        }
        
        /***************
         * CONSTRUCTOR 
         * @throws Exception *
         ***************/
        
        public Client(String scriptFile, String carRentalCompanyName) throws Exception {
                super(scriptFile);
                registry = LocateRegistry.getRegistry();
                sessionFactory = (SessionFactoryRemote)registry.lookup("SessionFactory");
        }

      

    @Override
    protected void addQuoteToSession(ClientSessionRemote session, Date start, Date end, String carType, String carRentalName) throws Exception {
        session.createQuote(start, end, carType, carRentalName);
    }

    @Override
    protected void confirmQuotes(ClientSessionRemote session) throws Exception {
        session.confirmQuotes();
    }

    @Override
    protected ClientSessionRemote getNewReservationSession(String name) throws Exception {
        return sessionFactory.createClientSession(name);
    }

    @Override
    protected ManagerSessionRemote getNewManagerSession(String name) throws Exception {
        return sessionFactory.getManagerSession();
    }

    @Override
    protected int getReservationsForCarType(ManagerSessionRemote ms, String carRentalCompanyName, String carType) throws Exception {
        return ms.getReservationsForCarType(carRentalCompanyName, carType);
    }
}
